package view.hero
{
import flash.display.MovieClip;

import framework.proxy.ComponentProxy;
import framework.view.components.graphics.SWF;

import values.avatar.AvatarAssetValue;
import values.avatar.AvatarEquipPosition;
import values.avatar.IAvatarValue;

import view.component.asset.SwfProxy;

/**
 * HeroAvatarDetailSkin
 * @author jliang
 *
 */
public class HeroAvatarDetailProxy extends ComponentProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function HeroAvatarDetailProxy()
	{
		super();
	}
	//==========================================================================
	//  Properties
	//==========================================================================
	protected var _data:IAvatarValue;

	public function get data():IAvatarValue
	{
		return _data;
	}

	public function set data(value:IAvatarValue):void
	{
		_data = value;
		
		skin.nameLabel.text = data.name;
		
		skin.descTF.text = data.avatarType.name;
		
		accessory.data = data.getEquipmentByPosition(AvatarEquipPosition.ACCESSORY);
		accessory.position = data.avatarType.getPositionByKey(AvatarEquipPosition.ACCESSORY);
		accessory.avatar = data;
		
		head.data = data.getEquipmentByPosition(AvatarEquipPosition.HEAD);
		head.position = data.avatarType.getPositionByKey(AvatarEquipPosition.HEAD);
		head.avatar = data;
		
		body.data = data.getEquipmentByPosition(AvatarEquipPosition.BODY);		
		body.position = data.avatarType.getPositionByKey(AvatarEquipPosition.BODY);
		body.avatar = data;
		
		shoe.data = data.getEquipmentByPosition(AvatarEquipPosition.SHOE);		
		shoe.position = data.avatarType.getPositionByKey(AvatarEquipPosition.SHOE);
		shoe.avatar = data;
		
		hand.data = data.getEquipmentByPosition(AvatarEquipPosition.HAND);		
		hand.position = data.avatarType.getPositionByKey(AvatarEquipPosition.HAND);
		hand.avatar = data;
		
		weapon.data = data.getEquipmentByPosition(AvatarEquipPosition.WEAPON);
		weapon.position = data.avatarType.getPositionByKey(AvatarEquipPosition.WEAPON);
		weapon.avatar = data;
		
		var asset:AvatarAssetValue = data.skinAsset;
		avatarSkin.load(asset.url, onAvatarSkinComplete, asset.assetMode, asset.classRef);
	}
	
	private function onAvatarSkinComplete(value:SwfProxy):void
	{
		(value.content as MovieClip).gotoAndStop(1);
	}
	
	public function get avatarSkin():SwfProxy
	{
		return proxys["avatar"];
	}
	
	public function get accessory():HeroEquipmentItemRenderProxy
	{
		return proxys["accessory"];
	}
	
	public function get head():HeroEquipmentItemRenderProxy
	{
		return proxys["head"];
	}
	
	public function get body():HeroEquipmentItemRenderProxy
	{
		return proxys["body"];
	}
	
	public function get shoe():HeroEquipmentItemRenderProxy
	{
		return proxys["shoe"];
	}
	
	public function get hand():HeroEquipmentItemRenderProxy
	{
		return proxys["hand"];
	}
	
	public function get weapon():HeroEquipmentItemRenderProxy
	{
		return proxys["weapon"];
	}
	//==========================================================================
	//  Overridden methods: RepeaterRenderProxy
	//==========================================================================	
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"avatar", classRef: SwfProxy, id:"avatar" },
			{ skin:"accessory", classRef: HeroEquipmentItemRenderProxy, id:"accessory" },
			{ skin:"head", classRef: HeroEquipmentItemRenderProxy, id:"head" },
			{ skin:"body", classRef: HeroEquipmentItemRenderProxy, id:"body" },
			{ skin:"shoe", classRef: HeroEquipmentItemRenderProxy, id:"shoe" },
			{ skin:"weapon", classRef: HeroEquipmentItemRenderProxy, id:"weapon" },
			{ skin:"hand", classRef: HeroEquipmentItemRenderProxy, id:"hand" }
		];
	}
	
	override public function dispose():void
	{
		_data = null;
		super.dispose();
	}
	
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
	}
	//==========================================================================
	//  Public methods
	//==========================================================================
	public function reset():void
	{
		accessory.reset();
		head.reset();
		body.reset();
		shoe.reset();
		weapon.reset();
		hand.reset();
		
		avatarSkin.stopAndRemove();
	}
}
}



